define(['PopUpBox'],function(){
	// checkbox
	var ViewImgBtn=function (){
		$('body').on('click','[data-viewimg]',function(){
			var $viewImgBox=$('<div class="viewImgBox text-center"></div>').css({
				width:0,
				height:0,
				overflow:'hidden'
			}).appendTo($('body'));
			var popUpBox=new PopUpBox({
				'type':'alert',
				'style':'default',
				'bgClose':true,
				'title':'查看大图',
				'content':''
			});
			var $this=$(this);
			$viewImg=$('<img src="'+$this.attr('data-viewimg')+'">').appendTo($viewImgBox);
			$viewImg.on('load',function(){
				var imgHasOverflow='';
				var viewImgSize={
					left:20,
					right:20,
					top:popUpBox.titleHeight+20,
					bottom:popUpBox.submitBtnBoxHeight+20
				}
				viewImgSize.width=$(window).width()-viewImgSize.left-viewImgSize.right;
				viewImgSize.height=$(window).height()-viewImgSize.top-viewImgSize.bottom;
				if($viewImg.width()>viewImgSize.width){
					$viewImg.width(viewImgSize.width);
					imgHasOverflow='width';
				}
				if($viewImg.height()>viewImgSize.height){
					$viewImg.height(viewImgSize.height);
					imgHasOverflow='height';
				}
				popUpBox.position={
					width:viewImgSize.width,
					height:viewImgSize.height
				};
				switch(imgHasOverflow){
					case 'width':
						$viewImg.css({
							position:'absolute',
							left:0,
							top:(viewImgSize.height-$viewImg.height())/2
						})
						break;
					case 'height':
						$viewImg.css({
							position:'absolute',
							left:(viewImgSize.width-$viewImg.width())/2,
							top:0
						})
						break;
				}
				popUpBox.$content.css({
					'min-width':'0'
				})
				$viewImgBox.removeAttr('style').css({
					position:'absolute',
					width:'100%',
					height:'100%',
					left:0,
					top:0,
					overflow:'hidden'
				}).appendTo(popUpBox.$content);

				popUpBox.show();

				if(imgHasOverflow){
					$viewImgBox.on('mousewheel',function(e,detail){
						var imgScaleSize=0;
						if(detail>0){
							imgScaleSize=50;
						}else if(detail<0){
							imgScaleSize=-50;
						}
						switch(imgHasOverflow){
							case 'width':
								$viewImg.width($viewImg.width()+imgScaleSize);
								$viewImg.css('margin-left',$viewImg.css('margin-left').replace('px','')-imgScaleSize/2);
								break;
							case 'height':
								$viewImg.height($viewImg.height()+imgScaleSize);
								$viewImg.css('margin-top',$viewImg.css('margin-top').replace('px','')-imgScaleSize/2);
								break;
						}
					})
					$viewImg.on('dragstart',function(ev){
						ev.preventDefault();
					});
					$viewImgBox.on('mousedown',function(e){
						WindowDrag.dragStart($viewImg,e)
					});
				}

			})
		})
	}
	ViewImgBtn();
	return ViewImgBtn;
})
